package com.gitee.cashzhang27.test.boot.activiti.controller;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.activiti.engine.ActivitiException;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * StencilsetRestResource.
 *
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/04/12 11:34
 */
@RestController
public class StencilsetRestResource {

  @RequestMapping(
      value = "/editor/stencilset",
      method = RequestMethod.GET,
      produces = "application/json;charset=utf-8")
  public @ResponseBody String getStencilset() {
    InputStream stencilsetStream =
        this.getClass().getClassLoader().getResourceAsStream("stencilset.json");
    try {
      return IOUtils.toString(stencilsetStream, StandardCharsets.UTF_8.name());
    } catch (Exception e) {
      throw new ActivitiException("Error while loading stencil set", e);
    }
  }
}
